package com.teradata.params.core.model;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

@Data
@NoArgsConstructor
@ToString
public class ApiMeta {
    private String apiId;
    private String apiName;
    private String dataSourceName;
    private ApiStateType apiStateType;
    private String mainStatement;
    private String followStatement;
    private Integer splitByDays;
    private Boolean isBlob;
    private Integer splitByNumOfCust;
    private Boolean isPersonalizedRpt;
    private Boolean isTreasuryRpt;
    private String idOfTreasury;
    private Boolean isSyn;
    private List<ColumnType> inParams;
    private List<ColumnType> outParams;


    @Test
    public void toJson() {
        ColumnType icolumnType1 = new ColumnType();
        icolumnType1.setParamType(ParamType.INPARAM);
        icolumnType1.setId(1);
        icolumnType1.setParamName("KHBH");
        icolumnType1.setParamDesc("客户编号");
        icolumnType1.setOrgiType(PrimitiveTypeKind.String);
        icolumnType1.setLengthPrecision("10");
        icolumnType1.setNote("由UAP提供");
        icolumnType1.setIsStartDate(false);
        icolumnType1.setIsEndDate(false);
        icolumnType1.setIsProxyCust(false);
        icolumnType1.setIsKey(false);

        ColumnType icolumnType2 = new ColumnType();
        icolumnType2.setParamType(ParamType.INPARAM);
        icolumnType2.setId(2);
        icolumnType2.setParamName("sUserId");
        icolumnType2.setParamDesc("经办人员编号");
        icolumnType2.setOrgiType(PrimitiveTypeKind.String);
        icolumnType2.setLengthPrecision("10");
        icolumnType1.setNote("由UAP提供");
        icolumnType2.setIsStartDate(false);
        icolumnType2.setIsEndDate(false);
        icolumnType2.setIsProxyCust(false);
        icolumnType2.setIsKey(false);


        ColumnType ocolumnType1 = new ColumnType();
        ocolumnType1.setParamType(ParamType.OUTPARAM);
        ocolumnType1.setId(14);
        ocolumnType1.setReturnParamName("ZLJYFX");
        ocolumnType1.setParamName("CshSttlemDrctn");
        ocolumnType1.setParamDesc("现金了结方向描述");
        ocolumnType1.setOrgiType(PrimitiveTypeKind.String);
        ocolumnType1.setLengthPrecision("10");
        ocolumnType1.setIsStartDate(false);
        ocolumnType1.setIsEndDate(false);
        ocolumnType1.setIsProxyCust(false);
        ocolumnType1.setIsKey(false);
        ocolumnType1.setCheckParamName("ZLYWLB");
        ocolumnType1.setIncludeValues("BT20");

        ColumnType ocolumnType2 = new ColumnType();
        ocolumnType2.setParamType(ParamType.OUTPARAM);
        ocolumnType2.setId(13);
        ocolumnType2.setReturnParamName("ZLJYFX");
        ocolumnType2.setParamName("TxDrctn");
        ocolumnType2.setParamDesc("交易方向描述");
        ocolumnType2.setOrgiType(PrimitiveTypeKind.String);
        ocolumnType2.setLengthPrecision("10");
        ocolumnType2.setIsStartDate(false);
        ocolumnType2.setIsEndDate(false);
        ocolumnType2.setIsProxyCust(false);
        ocolumnType2.setIsKey(false);
        ocolumnType2.setCheckParamName("ZLYWLB");
        ocolumnType2.setExcludeValues("BT20,BTA7");

        ApiMeta apiMeta = new ApiMeta();
        apiMeta.setApiId("0030000001");
        apiMeta.setApiName("指令询");
        apiMeta.setDataSourceName("datagate_bj");
        apiMeta.setApiStateType(ApiStateType.NORMAL);
        apiMeta.setMainStatement("{CALL RUN08091.P00300001A(?,?,?,?,?,?,?,?,?,?)}");
        apiMeta.setFollowStatement("{CALL RUN08091.P00300001B(?,?,?,?,?,?,?,?,?,?)}");
        apiMeta.setSplitByDays(30);
        apiMeta.setIsBlob(false);
        apiMeta.setIsPersonalizedRpt(false);
        apiMeta.setIsTreasuryRpt(false);
        apiMeta.setIsSyn(false);
        apiMeta.setInParams(Arrays.asList(icolumnType1,icolumnType2));
        apiMeta.setOutParams(Arrays.asList(ocolumnType1,ocolumnType2));

        String jsonString = JSONObject.toJSONString(apiMeta);
        System.out.println(jsonString);
    }

}
